<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>商品分类选择</title>
<%@ include file="/page/include.jsp"%>
<link href="<%=basePath%>/statics/css/webform.css?v=20180104" rel="stylesheet" />
<link href="${rootPath }/statics/plugins/zTree/css/metroStyle/metroStyle.css" rel="stylesheet">
</head>
<body class="nav-md">
	<div class="container body">
		<div class="main_container">
			<div class="framebody" role="main">
				<!-- <div class="row" style="padding-top:10px;">
					<div class="col-md-12" style="width: 90%;">
						<input id="productCategoryId" name="productCategoryId" class="form-control col-md-12" placeholder="商品分类" type="text">
					</div>
				</div> -->
				<div class="row">
					<div class="col-md-12" style="width: 90%;">
						<ul class="ztree" id="zTree">
						</ul>
					</div>
				</div>
				<div class="row" style="padding-top: 10px; text-align: center;">
					<div class="col-md-12 txtCenter" style="width: 100%;">
						<!-- <button id="btnOk" class="btn btn-primary">确定</button> -->
						<button id="btn_back" class="btn btn-waring">关闭</button>
					</div>
				</div>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript" src="${rootPath }/statics/plugins/zTree/js/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript" src="${rootPath }/statics/js/jquery-ztree-combobox-1.0.0.js"></script>
<script type="text/javascript">
	$(function() {
		/* $('#productCategoryId').comboboxTree({
			id : "productCategoryId",
			url : rootPath + '/productCategory/categoryTree',
			// param: [], //请求参数
			idKey : 'id', // 下拉框树节点id，默认值为id
			pIdKey : 'pid', // 下拉框树节点父id，默认值为pid
			rootPId : "0", // 根节点值,默认值为0
			nameKey : 'name'// , //文本key
		}); */

		/**
		 * zTree设置
		 */
		var setting = {
			check : {
				enable : false,//禁用checkbox
				chkboxType : {
					"Y" : "ps",
					"N" : "ps"
				}
			},
			callback : {
				onClick : zTreeOnClick
			},
			data : {
				key : {
					name : "name"
				},
				simpleData : {
					enable : true,
					idKey : 'id',
					pIdKey : 'pid',
					rootPId : "0"
				}
			}
		};

		$.ajax({
			url : rootPath + "/productCategory/categoryTree",
			async : false,
			dataType : 'json',
			type : 'post',
			success : function(nodes) {
				if (nodes) {
					var treeObj = $.fn.zTree.init($("#zTree"), setting, nodes);
					treeObj.expandAll(false);
				}
			},
			fail : function() {
				msg("资源树加载失败");
			}
		});
	});
	/**
	 * 点击事件
	 */
	function zTreeOnClick(event, treeId, treeNode) {
		if (treeNode.id && treeNode.name) {
			parent.$('#productCategoryId').val(treeNode.id);
			parent.$('#productCategoryName').val(treeNode.name);
			var index = parent.layer.getFrameIndex(window.name);
			parent.layer.close(index);
		}
	};

	//关闭
	$("#btnOk").click(function() {
		var productCategoryId = $("#productCategoryId").attr("bind-data");
		var productCategoryName = $("#productCategoryId").val();
		if (productCategoryId && productCategoryName) {
			parent.$('#productCategoryId').val(productCategoryId);
			parent.$('#productCategoryName').val(productCategoryName);
		}
		var index = parent.layer.getFrameIndex(window.name);
		parent.layer.close(index);
	});
	//关闭
	$("#btn_back").click(function() {
		var index = parent.layer.getFrameIndex(window.name);
		parent.layer.close(index);
	});
</script>
</html>